package com.ygl.common.api;

import com.ygl.constants.BaseApiConstants;

import java.util.HashMap;
import java.util.Map;

/**
 * @author： ygl
 * @date： 2019/02/02
 * @Description：
 */
public class BaseApiResponse {

    /**
     * 返回错误
     * @param msg 错误提示
     * @return
     */
    public Map<String, Object> setResponseError(String msg) {
        return setResponse(BaseApiConstants.HTTP_500_CODE, msg, null);
    }

    /**
     * 返回成功 (带返回数据)
     * @param data 返回数据
     * @return
     */
    public Map<String, Object> setResponseSuccessData(Object data) {
        return setResponse(BaseApiConstants.HTTP_200_CODE, BaseApiConstants.HTTP_SUCCESS_NAME, data);
    }

    /**
     * 返回成功 (无自定义数据)
     * @return
     */
    public Map<String, Object> setResponseSuccess() {
        return setResponse(BaseApiConstants.HTTP_200_CODE, BaseApiConstants.HTTP_SUCCESS_NAME, null);
    }

    /**
     * 返回成功 (带返回提示)
     * @param msg
     * @return
     */
    public Map<String, Object> setResponseSuccess(String msg) {
        return setResponse(BaseApiConstants.HTTP_200_CODE, msg, null);
    }

    /**
     *
     * @methodDesc: 功能描述:(返回成功)
     * @param: @param
     *             msg
     * @param: @return
     */
    public Map<String, Object> setResponseParameterError(String msg) {
        return setResponse(BaseApiConstants.HTTP_400_CODE, msg, null);
    }

    /**
     * 自定义返回
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public Map<String, Object> setResponse(Integer code, String msg, Object data) {
        Map<String, Object> result = new HashMap<>();
        result.put(BaseApiConstants.HTTP_CODE_NAME, code);
        result.put(BaseApiConstants.HTTP_200_NAME, msg);
        if (data != null) {
            result.put(BaseApiConstants.HTTP_DATA_NAME, data);
        }
        return result;
    }
}
